<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>数据</el-breadcrumb-item>
        <el-breadcrumb-item>书籍</el-breadcrumb-item>
        <el-breadcrumb-item>新用户书籍留存</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud 
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange" 
        @search-reset="from = {}"
        @search-change="searchChange">
        <template :slot="'retain'+(i)" v-for="i in 30"   slot-scope="scope">
          <span :key="i">{{ scope.row["retain"+(i)] }}%</span>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { appStatisticsBook as baseURL,bookCategory } from "@/api/cat/baseUrls"; 
export default { 
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10,
      },
      type: true,
      data: [],
      params: {},
      form: {},
      default: {
        orderByList: "statistics_date&DESC",
        user_type: 1
      },
      option: {
        border: true,
        index: true,
        indexLabel: "编号",
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        excelBtn: true,
        selection: true,
border: true,
        menu: false,
        column: [
         {
            label: "日期",
            prop: "statistics_date_search",
            type: "daterange",
            search: true,
            hide:true,
          },
          {
            label: "日期",
            prop: "statistics_date",
            type: "date",
            format:"yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            search: false, 
            width: '55px'
          }, 
          {
            label: "分类",
            prop: "category_id_1",
            type: "select",
            search: true,
            dicUrl: `${catUrl + bookCategory.getListByLeave}/1`,
            placeholder: "分类",
            dicFormatter: (res) => {
              return res.source;
            },
            props: {
              label: "label",
              value: "value",
            },
            span:9
          },
          {
            label: "图书id",
            prop: "book_id",
            type: "input",
            search: true,
            width: '35px'
          },
          {
            label: "图书名称",
            prop: "book_name",
            type: "input",
            search: true,
            width: '40px'
          },
          {
            label: "阅读人数",
            prop: "read_user_num",
            type: "input",
            width: '40px'
          },
          {
            label: "次日留存",
            prop: "retain1",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "2日留存",
            prop: "retain2",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "3日留存",
            prop: "retain3",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "4日留存",
            prop: "retain4",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "5日留存",
            prop: "retain5",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "6日留存",
            prop: "retain6",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "7日留存",
            prop: "retain7",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "8日留存",
            prop: "retain8",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "9日留存",
            prop: "retain9",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "10日留存",
            prop: "retain10",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "11日留存",
            prop: "retain11",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "12日留存",
            prop: "retain12",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "13日留存",
            prop: "retain13",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "14日留存",
            prop: "retain14",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "15日留存",
            prop: "retain15",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "16日留存",
            prop: "retain16",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "17日留存",
            prop: "retain17",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "18日留存",
            prop: "retain18",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "19日留存",
            prop: "retain19",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "20日留存",
            prop: "retain20",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "21日留存",
            prop: "retain21",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "22日留存",
            prop: "retain22",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "23日留存",
            prop: "retain23",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "24日留存",
            prop: "retain24",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "25日留存",
            prop: "retain25",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "26日留存",
            prop: "retain26",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "27日留存",
            prop: "retain27",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "28日留存",
            prop: "retain28",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "29日留存",
            prop: "retain29",
            type: "input",
            width: '51px',
            slot: true
          },
          {
            label: "30日留存",
            prop: "retain30",
            type: "input",
            width: '51px',
            slot: true
          }
        ]
      }
    };
  },
  methods: {
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(
        baseURL.appDay30List,
        { ...this.params, ...this.default },
        this.page,
        "POST"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    } /**刷新 */,
    refreshChange() {
      this.getList();
    },
    /**搜索 */
    searchChange(params, done) {
      params.statistics_date = `${params.statistics_date_search ? "!<>!" + params.statistics_date_search : ""}`
      params.book_name = `${params.book_name?"%"+params.book_name+"%":""}`
      delete params.statistics_date_search;
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    }
  },
};
</script>